Skip to content

Conversation

@mcruzdev
Copy link
Contributor

Changes

  • Add a new RuntimeException the the serverlessworkflow-impl-http module called RedirectValidationException.
  • Add a new method into AbstractHttpExecutorBuilder responsible for applying redirect validation rules for the HTTP response. When the validation fails, it pass the response status code to the WorkflowError instance.

TODO

  • Add specific tests for redirect behavior (when the upstream server returns a 3XX status code)

Closes #959

Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
Comment on lines 49 to 51
case HttpMethod.PATCH:
return new WithBodyRequestSupplier(
(request, entity) -> request.method("patch", entity), application, body, redirect);
Copy link
Contributor Author

@mcruzdev mcruzdev Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to discuss about PATCH, I will write some options tomorrow 🛌🏼

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI folks, I did not have time to solve this one. My new changes:

  • Add tests for DELETE, HEAD, PUT and OPTIONS
  • Use one method by CNCF Specification file
  • Remove for now the support for PATCH

I removed the support for PATCH just to find a better solution for it, actually the HTTP client lib we are using, uses the java.net.HttpURLConnection that does not support PATCH methods. To achieve it, we have some workarounds:

  • To use a property HttpUrlConnectorProvider.SET_METHOD_WORKAROUND but it uses reflection behind the scenes and it is necessary to use --add-opens. (it need an extra configuration)
  • Use X-HTTP-Method-Override header (in my opnion, it is a bad idea, it is not guaranteed solution)
  • Add a new library that supports PATCH with no friction.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ricardozanini @fjtirado do you have another solution in mind?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jersey won't support it, but RestEasy does, for example. The SDK relies on Jersey by default, but downstream clients can override the HttpClient. So it's not always true.

If Jersey, we just fire an UnsupportedOperation exception, or let the HTTP client implementation do so. Document it so users know that the default HTTP client shipped with the SDK does not support PATCH.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, jersey is only used for testing and explicitly added in examples, it is not really a dependency of the SDK

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fjtirado but if I use the SDK standalone and once the code reaches Client.newBuilder, it explodes if there's no implementation in the classpath?


if (!redirect) {
// disable automatic redirects handling from Jersey client
request.property("jersey.config.client.followRedirects", false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't tie our implementation to this client. Dowstream client code can override the HTTP client factory, hence it won't be Jersey.

We could have a supplier here where the downstream client can be called to react to this property instead.

By default, we set the jersey property or let the supplier from the underlying client do so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't tie our implementation to this client. Dowstream client code can override the HTTP client factory, hence it won't be Jersey.

Yeah, I forget this spec/impl detail.

We could have a supplier here where the downstream client can be called to react to this property instead.

Do you mean a new method WorkflowApplication.Builder method or a ServiceProvider?

Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
@fjtirado
Copy link
Collaborator

@mcruzdev
For the PATCH thing I agree with Ricardo, let the implementation as it was, if the client does not support patch, so be it.
Regarding redirect configuration, I need to think, lets take some time to consider the alternatives.

Comment on lines +65 to +73
WorkflowError.communication(
response.getStatus(),
task,
String.format(
"The property 'redirect' is set to %s but received status %d (%s); expected status in the %s range",
redirect,
response.getStatus(),
response.getStatusInfo().getReasonPhrase(),
expectedRange))
Copy link
Collaborator

@fjtirado fjtirado Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, lets keep the prevvious code,
Why?, because I feel is more interesting to extract the error message from the response (give potentially a lot of more info to the user) rather than explain why we are throwing the error when redirect is enable, that should be self explanatory by looking at the status code

Comment on lines +58 to +62
boolean isSuccess = statusFamily.equals(SUCCESSFUL);
boolean isRedirect = statusFamily.equals(REDIRECTION);
boolean valid = redirect ? (isSuccess || isRedirect) : isSuccess;

if (!valid) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simplify the condition, we want to fail if the call was not successful or if redirect flag is false and the status was a redirection one.

Suggested change
boolean isSuccess = statusFamily.equals(SUCCESSFUL);
boolean isRedirect = statusFamily.equals(REDIRECTION);
boolean valid = redirect ? (isSuccess || isRedirect) : isSuccess;
if (!valid) {
if (statusFamily != SUCCESSFUL || !isRedirect && status == REDIRECTION) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add redirect for OpenAPI call

3 participants